//
//  CustomTabbarViewController.m
//  Student
//
//  Created by kwsdzjx on 15/10/8.
//  Copyright © 2015年 周佳兴. All rights reserved.
//

//#ifdef Main
////NSLog(@"主项目程序");
//#import "TabBarOccupyingController.h"
//#elif Student
////NSLog(@"学员端程序");
//
//#import "TabBarOccupyingController1.h"
//#elif Teacher
////NSLog(@"老师端程序");
//#else
////NSLog(@"都不是");
//#endif



#import "TabBarOccupyingController.h"
#import "TabBarOccupyingController1.h"
#import "CustomTabbarViewController.h"
#import "Masonry.h"
#import "FunctionMenuViewController.h"

//#import "OfficeBoardViewController.h"
#import "StudentMoreViewController.h"


#import "ThingsViewController.h"
#import "NewScheduleController.h"
//#import "OfficeBoardViewController.h"
#define kScreenWidth [UIScreen mainScreen].bounds.size.width
@interface CustomTabbarViewController ()
@property(strong, nonatomic)CustomViewController *cusTabView;
@property(strong,nonatomic)UILabel               *requeatResultLabel;
@end

@implementation CustomTabbarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    if([[[NSUserDefaults standardUserDefaults]objectForKey:@"remember"]isEqualToString:@"remember"]){
//        [self loginBtnClick];
    }
    [self createUI];
    [self cerateControllers];

}

-(void)cerateControllers{
    //***创建装控制器的arr
    NSMutableArray *mutVCArr = [[NSMutableArray alloc] init];
    
    FunctionMenuViewController *thingVC;
    ThingsViewController *svc;
    
    //***事物看板页面
//#ifdef Main
    
    if([getUIStyle()isEqualToString:STYLE0]){
    //    NSLog(@"主项目程序");
    thingVC = [[FunctionMenuViewController alloc] init];
    svc = [[ThingsViewController alloc] init];
    //#import "TabBarOccupyingController.h"
    }else{
//#elif Student
    //    NSLog(@"学员端程序");
    thingVC = [[FunctionMenuViewController alloc] init];
    svc = [[ThingsViewController alloc] init];
    }

    
    thingVC.cusTabView = self.cusTabView;
    UINavigationController *thingsVCNav1 = [[UINavigationController alloc] initWithRootViewController:thingVC];
    //    svc.selfNav = svcNav;
    [mutVCArr addObject:thingsVCNav1];

    //***创建主页面栏目页面
    

    
    svc.cusTabView = self.cusTabView;
//    svc.tbView1 = self.cusTabView;
    UINavigationController *svcNav = [[UINavigationController alloc] initWithRootViewController:svc];
//    svc.selfNav = svcNav;
    if([getUIStyle()isEqualToString:STYLE1]){
        [mutVCArr addObject:svcNav];
    }
    

    //***创建主页面
//#ifdef Main
if([getUIStyle()isEqualToString:STYLE0]){
//    //    NSLog(@"主项目程序");
    ThingsViewController *tabBarVC2 = [[ThingsViewController alloc] init];
    
    tabBarVC2.cusTabView = self.cusTabView;
    
    UINavigationController *tabBarVCNav2 = [[UINavigationController alloc] initWithRootViewController:tabBarVC2];
    
    //    svc.selfNav = svcNav;
    [mutVCArr addObject:tabBarVCNav2];
#pragma mark - 出现课程表   卓美项目隐藏课程表
//    TabBarOccupyingController1 *tabBarVC1 = [[TabBarOccupyingController1 alloc] init];
//    tabBarVC1.isHadTabbar = YES;
    NewScheduleController *tabBarVC1 = [[NewScheduleController alloc] init];
    
    tabBarVC1.cusTabView = self.cusTabView;
    
    UINavigationController *tabBarVCNav1 = [[UINavigationController alloc] initWithRootViewController:tabBarVC1];
    
    //    svc.selfNav = svcNav;
    if([rolenames() isEqualToString:@"教师"]){
      [mutVCArr addObject:tabBarVCNav1];
    }
    
    
    StudentMoreViewController *sthVC = [[StudentMoreViewController alloc] init];
    sthVC.cusTabView = self.cusTabView;
    UINavigationController *stuVCNav1 = [[UINavigationController alloc] initWithRootViewController:sthVC];
    //    svc.selfNav = svcNav;
    [mutVCArr addObject:stuVCNav1];
#pragma mark - 出现课程表end

}else{

    
    TabBarOccupyingController1 *tabBarVC1 = [[TabBarOccupyingController1 alloc] init];
    tabBarVC1.isHadTabbar = YES;
    
    tabBarVC1.cusTabView = self.cusTabView;
    
    UINavigationController *tabBarVCNav1 = [[UINavigationController alloc] initWithRootViewController:tabBarVC1];
    
    //    svc.selfNav = svcNav;
    [mutVCArr addObject:tabBarVCNav1];
    
    StudentMoreViewController *sthVC = [[StudentMoreViewController alloc] init];
    sthVC.cusTabView = self.cusTabView;
    UINavigationController *stuVCNav1 = [[UINavigationController alloc] initWithRootViewController:sthVC];
    //    svc.selfNav = svcNav;
    [mutVCArr addObject:stuVCNav1];
}

//#endif
    
    
//#ifdef Main
//    NSLog(@"主项目程序");
//#elif Student
//    NSLog(@"学员端程序");
//    //***学员端更多页面
//    
////        StudentMoreViewController *sthVC = [[StudentMoreViewController alloc] init];
////        sthVC.cusTabView = self.cusTabView;
////        UINavigationController *stuVCNav1 = [[UINavigationController alloc] initWithRootViewController:sthVC];
////        //    svc.selfNav = svcNav;
////        [mutVCArr addObject:stuVCNav1];
//    
//#elif Teacher
//    NSLog(@"老师端程序");
//#else
//    NSLog(@"都不是");
//#endif
    self.viewControllers = mutVCArr;
    
    
    
}




-(void)createUI{
    self.tabBar.hidden = YES;
    CGRect rect = CGRectMake(0, [UIScreen mainScreen].bounds.size.height - 49, [UIScreen mainScreen].bounds.size.width, 49);
    CustomViewController *tbView = [[CustomViewController alloc]initWithFrame:rect andReturnSelectIndex:^(NSInteger selectB) {
        self.selectedIndex = selectB;
    }];
//    tbView.backgroundColor = [UIColor redColor];
    [self.view addSubview:tbView];
    self.cusTabView = tbView;
//    [tbView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(@(0));
//        make.right.equalTo(self.view.mas_right);
//        make.height.equalTo(@(49));
//        make.bottom.equalTo(self.view.mas_bottom);
//    }];
    
    tbView.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height-49, [UIScreen mainScreen].bounds.size.width, 49);
    
#warning TEXT
    [tbView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.bottom.equalTo(self.view.mas_bottom);
        make.height.equalTo(@(49));
    }];
}


#pragma mark - loginButton click
-(void)loginBtnClick{
    
    NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
    NSString *userStr = [userDefault objectForKey:@"user"];
    NSString *passStr = [userDefault objectForKey:@"pass"];
    NSMutableDictionary *parmas = [[NSMutableDictionary alloc]init];
    [parmas setObject:userStr forKey:@"studentPhone"];
    [parmas setObject:passStr forKey:@"stuPassword"];
    NSString *requestStr = [NSString stringWithFormat:@"%@%@", getBase(), LOGIN_URL];
    [NetRequest requestUrl:requestStr andParamas:parmas andReturnBlock:^(NSData *data, NSError *error) {
        if(!error&&data!=nil){
            
        }
        else{
            
            [[NSNotificationCenter defaultCenter]postNotificationName:@"login" object:@"Exit"];
        }
    }];
    
}

-(void)showLabelWithText:(NSString *)text{
    if(self.requeatResultLabel!=nil)return;
    self.requeatResultLabel = [[UILabel alloc]init];
    self.requeatResultLabel.backgroundColor = [UIColor colorWithRed:30/255.0 green:25/255.0 blue:77/255.0 alpha:0.4];
    self.requeatResultLabel.textColor = [UIColor whiteColor];
    self.requeatResultLabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:self.requeatResultLabel];
    self.requeatResultLabel.frame = CGRectMake(0, 0, self.view.bounds.size.width, 0);
    CGRect frame = self.requeatResultLabel.frame;
    self.requeatResultLabel.text = [NSString stringWithFormat:@"%@", text];
    self.requeatResultLabel.font = [UIFont systemFontOfSize:14];
    [self.view bringSubviewToFront:self.requeatResultLabel];
    [UIView animateWithDuration:0.5 animations:^{
        self.requeatResultLabel.frame = CGRectMake(0, 0, self.view.bounds.size.width, 25);
        
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:2.0 animations:^{
            self.requeatResultLabel.frame = frame;
        } completion:^(BOOL finished) {
            [self.requeatResultLabel removeFromSuperview];
            self.requeatResultLabel = nil;
        }];
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
